package standino.velocity.db.db2;

import java.util.List;

import standino.velocity.db.db2.template.Generator;
import standino.velocity.db.db2.template.TemplateMapping;

public class GenSQL {

	public void gen(String defFile, String destDir) {

		TableBuilder builder = new TableBuilder();
		TemplateMapping map = TemplateMapping.getInstance();
		builder.build(defFile);
		Table table = builder.getTable();
		Generator gn = new Generator(destDir + "/" + table.getName() + ".SQL",
				map.getTemplate(table.getType()));
		gn.gen("table", builder.getTable());
		List<SP> sp = builder.getSps();
		for (SP s : sp) {
			gn = new Generator(destDir + "/" + s.getName() + ".SQL", map
					.getTemplate(s.getType()));
			gn.gen("sp", s);
		}

	}

	public static void main(String[] args) {
		GenSQL gn = new GenSQL();
		if (args.length < 2) {
			System.out.println("java -jar gensql.jar table.def  c:\\");
		} else {
			gn.gen(args[0], args[1]);
		}
	}
}
